// 通用通知组件
function showToast(message, type = 'success') {
    // 创建toast元素
    const toast = document.createElement('div');
    toast.className = `fixed top-6 right-6 px-6 py-3 rounded-lg shadow-lg z-50 transition-all duration-300 transform translate-x-full`;
    
    // 设置样式
    if (type === 'success') {
        toast.className += ' bg-green-100 text-green-800 border border-green-200';
    } else if (type === 'error') {
        toast.className += ' bg-red-100 text-red-800 border border-red-200';
    } else if (type === 'warning') {
        toast.className += ' bg-yellow-100 text-yellow-800 border border-yellow-200';
    } else {
        toast.className += ' bg-blue-100 text-blue-800 border border-blue-200';
    }
    
    // 设置内容
    toast.innerHTML = `
        <div class="flex items-center gap-2">
            <i class="fas fa-${type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-circle' : type === 'warning' ? 'exclamation-triangle' : 'info-circle'}"></i>
            <span>${message}</span>
        </div>
    `;
    
    // 添加到页面
    document.body.appendChild(toast);
    
    // 显示动画
    setTimeout(() => {
        toast.classList.remove('translate-x-full');
    }, 100);
    
    // 自动关闭
    setTimeout(() => {
        toast.classList.add('translate-x-full');
        setTimeout(() => {
            document.body.removeChild(toast);
        }, 300);
    }, 3000);
}

// 加载状态管理
function showLoading() {
    // 创建加载遮罩
    const loadingOverlay = document.createElement('div');
    loadingOverlay.id = 'loadingOverlay';
    loadingOverlay.className = 'fixed inset-0 bg-white bg-opacity-70 flex items-center justify-center z-50';
    
    // 创建加载动画
    const spinner = document.createElement('div');
    spinner.className = 'w-12 h-12 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin';
    
    loadingOverlay.appendChild(spinner);
    document.body.appendChild(loadingOverlay);
}

function hideLoading() {
    const loadingOverlay = document.getElementById('loadingOverlay');
    if (loadingOverlay) {
        loadingOverlay.remove();
    }
}

// 密码强度检测
function checkPasswordStrength(password) {
    let strength = 0;
    if (password.length >= 8) strength++;
    if (/[a-z]/.test(password)) strength++;
    if (/[A-Z]/.test(password)) strength++;
    if (/[0-9]/.test(password)) strength++;
    if (/[^a-zA-Z0-9]/.test(password)) strength++;
    
    return strength;
}

// 格式化日期
function formatDate(date) {
    const d = new Date(date);
    return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}

// 加密显示文本
function maskText(text, showFirst = 4, showLast = 4) {
    if (!text || text.length <= showFirst + showLast) {
        return '*'.repeat(text.length);
    }
    return text.substring(0, showFirst) + '*'.repeat(text.length - showFirst - showLast) + text.substring(text.length - showLast);
}

// 生成唯一ID
function generateId(prefix = 'ID') {
    return `${prefix}-${Date.now().toString(36)}${Math.random().toString(36).substr(2, 5)}`;
}